/**
 *
 */
package ua.at.tsvetkov.samizdat.activities;

import ua.at.tsvetkov.samizdat.adapters.AdtFavoriteAuthors;
import ua.at.tsvetkov.samizdat.data.DataLoadedAuthors;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

/**
 * @author A.Tsvetkov 2011, http://tsvetkov.at.ua, al@ukr.net
 */
public class AcFavoriteAuthors extends AcTemplate {

	private DataLoadedAuthors	dataLoadedAuthors;
	private AdtFavoriteAuthors	adtLoadedAuthors;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		addListView();
		dataLoadedAuthors = new DataLoadedAuthors(this);
		dataLoadedAuthors.loadFavorite();
		if (dataLoadedAuthors.authorsData.length == 0) {
			Toast.makeText(this, "Загрузок пока нет.", Toast.LENGTH_LONG);
			finish();
		}
		adtLoadedAuthors = new AdtFavoriteAuthors(dataLoadedAuthors.authorsData);
		listView.setAdapter(adtLoadedAuthors);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Intent intent = new Intent(AcFavoriteAuthors.this, AcLoadedAuthorBooks.class);
				intent.putExtra("author", dataLoadedAuthors.authorsData[position].author);
				startActivity(intent);
			}

		});
	}

}
